package core;

import fileoperation.FileDeletion;
import repository.Repository;
import stage.Index;

import java.io.File;
import java.io.IOException;

public class JitRm {
    /**
     * remove from working area and index
     */
    public static void remove(String filename) throws IOException {
        removeCached(filename);
        if (!new File(Repository.getWorkTree() + File.separator + filename).exists()){
            System.out.println("File "+ filename + " doesn't exist in working area.");
            return;
        }
        FileDeletion.deleteFile(Repository.getWorkTree() + File.separator + filename);
        System.out.println("Remove file "+ filename + " from working area.");
    }
    /**
     * remove from index
     */
    public static void removeCached(String filename) throws IOException{
        Index index = new Index();
        index.remove(filename);
    }
}
